package com.minyifang.wcspf.work.dialog.presenter;

import com.minyifang.wcspf.common.base.BasePresenter;
import com.minyifang.wcspf.common.config.network.Constants;
import com.minyifang.wcspf.common.config.network.RetrofitHelper;
import com.minyifang.wcspf.common.config.user.UserManager;
import com.minyifang.wcspf.work.dialog.view.AddToCarView;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by LuoYaWei on 2018/7/25.
 */
public class AddToCarPresenter extends BasePresenter<AddToCarView> {

    public void getSpecification(String id) {
        Map<String, Object> map = new HashMap<>();
        map.put("comId", id);

        JSONObject jsonData = Constants.getAESJsonData(map, UserManager.getInstance().getToken());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().getSpecification(requestBody), respond -> getView().showSpecificationRes(respond));
    }

    public void addToCar(String skuId, String mscQuantity) {
        Map<String, Object> map = new HashMap<>();
        map.put("skuId", skuId);
        map.put("quantity", mscQuantity);
        JSONObject jsonData = Constants.getAESJsonData(map, UserManager.getInstance().getToken());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().addToCar(requestBody),stringHttpRespond -> getView().showAddToCarRes(stringHttpRespond));
    }
}
